package com.chinaunicom;

import com.chinaunicom.constructor.Car;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/11/16 21:44
 * Description:
 */
public class Application {

	public static void main(String[] args) {

		Resource resource = new ClassPathResource("beans.xml");

		// 创建 bean 工厂类
		BeanFactory beanFactory = new DefaultListableBeanFactory();

		// beanFactory 封装成  xmlBeanDefinition 解析类 xmlBeanDefinitionReader
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);

		// 解析资源文件
		reader.loadBeanDefinitions(resource);

		Car car = (Car) beanFactory.getBean("car");
		System.out.println(car.toString());


		/***
		Person person = (Person) beanFactory.getBean("person");

		System.out.println(person);


		GetBeanTest beanTest= (GetBeanTest) beanFactory.getBean("getBeanTest");
		beanTest.showMe();


		TestChangeMethod changeMethod = (TestChangeMethod) beanFactory.getBean("testChangeMethod");
		changeMethod.changeMe();

		*/
	}
}
